package com.tenbent.product.base.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 过滤器 （过滤请求是否需要登录）
 *
 * @author Randy
 *
 *         Created by ThinkPad on 2017/7/25.
 */
public class TenbentFilter extends OncePerRequestFilter {

	private Logger logger = LoggerFactory.getLogger(TenbentFilter.class);

	/** 非必须登录页面 */
	private String[] nonLoginUrls;

	public TenbentFilter() {

	}

	public TenbentFilter(String[] nonLoginUrls) {
		this.nonLoginUrls = nonLoginUrls;
	}

	@Override
	protected void doFilterInternal(HttpServletRequest req, HttpServletResponse reps, FilterChain filterChain)
			throws ServletException, IOException {
		logger.info("request is in doFilter(TenbentFilter).....!");
		// TODO 写具体的过滤逻辑(根据属性 例如 nonLoginUrls
		// TODO 登录页面不需要过滤，别的请求需要登录后才能调用，否则重定向到登录页面等，API请求不需要过滤等逻辑属性)
		filterChain.doFilter(req, reps);
	}

	public String[] getNonLoginUrls() {
		return nonLoginUrls;
	}

	public void setNonLoginUrls(String[] nonLoginUrls) {
		this.nonLoginUrls = nonLoginUrls;
	}
}
